﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;

namespace GUI.mngsys
{
    using EXT;
    using BLL;
    using DAL.Entities;
    public partial class frmInsertTTP : GUI.Danhmuc.frmInputDanhmuc
    {
        public frmInsertTTP()
        {
            InitializeComponent();
        }
        TrangthaiphieuBLL Trangthaiphieu_BLL = new TrangthaiphieuBLL();

        public byte[] PictureToArray(PictureBox ptc)
        {
            MemoryStream ms = new MemoryStream();
            ptc.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms.ToArray();
        }

        public MemoryStream _MemoryStream(byte[] ByteHinh)
        {
            return new MemoryStream(ByteHinh);
        }

        public Image ArrayToPicture( byte[] Array_Image)
        {
            return Image.FromStream(_MemoryStream(Array_Image));
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (!Trangthaiphieu_BLL.IsExists())
            {
                Trangthaiphieu_BLL._sqlMapper.BeginTransaction();
                Trangthaiphieu ttp = new Trangthaiphieu();

                ttp.Id = new Guid("a864d689-7c31-4bf4-b009-0405cfadef99");
                ttp.Ten = "Phiếu chưa có hàng";
                ptcTemp.Image = global::GUI.Properties.Resources.Chuacohang;
                ttp.Hinh = PictureToArray(ptcTemp);
                Trangthaiphieu_BLL.Trangthaiphieu_Insert(ttp);

                ttp.Id = new Guid("a864d689-7c31-4bf4-b009-0405cfadef98");
                ttp.Ten = "Chưa thanh toán";
                ptcTemp.Image = global::GUI.Properties.Resources.Chuatra;
                ttp.Hinh = PictureToArray(ptcTemp);
                Trangthaiphieu_BLL.Trangthaiphieu_Insert(ttp);

                ttp.Id = new Guid("a864d689-7c31-4bf4-b009-0405cfadef97");
                ttp.Ten = "Vẩn còn nợ";
                ptcTemp.Image = global::GUI.Properties.Resources.Dangtra;
                ttp.Hinh = PictureToArray(ptcTemp);
                Trangthaiphieu_BLL.Trangthaiphieu_Insert(ttp);

                ttp.Id = new Guid("a864d689-7c31-4bf4-b009-0405cfadef96");
                ttp.Ten = "Đã thanh toán xong";
                ptcTemp.Image = global::GUI.Properties.Resources.Datra;
                ttp.Hinh = PictureToArray(ptcTemp);
                Trangthaiphieu_BLL.Trangthaiphieu_Insert(ttp);
                Trangthaiphieu_BLL._sqlMapper.CommitTransaction();
                gcDanhsach.DataSource = Trangthaiphieu_BLL.Trangthaiphieu_Select();
            }
            else MsgC.MsgOK("Khỏai cần thêm nữa chú ơi, cóa rầu ^^");
        }

        private void frmInsertTTP_Load(object sender, EventArgs e)
        {
            gcDanhsach.DataSource = Trangthaiphieu_BLL.Trangthaiphieu_Select();
        }
    }
}
